﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using GiveAQuizSite;
using GiveAQuizSite.Controllers;
using GiveAQuiz.Data;
using Autofac;
using Moq;

namespace GiveAQuizSite.Tests.Controllers
{
  [TestClass]
  public class HomeControllerTest
  {
    IContainer theContainer;
    HomeController theController;
    
    [TestInitialize]
    public void Init()
    {
      var builder = new ContainerBuilder();
      builder.Register<IQuizRepository>((ctx) => new Mock<IQuizRepository>().Object);
      builder.RegisterType<HomeController>();
      theContainer = builder.Build();
      theController = theContainer.Resolve<HomeController>();
    }

    [TestMethod]
    public void Index()
    {
      // Act
      ViewResult result = theController.Index() as ViewResult;

      // Assert
      ViewDataDictionary viewData = result.ViewData;
      Assert.AreEqual("Welcome to ASP.NET MVC!", viewData["Message"]);
    }

    [TestMethod]
    public void About()
    {
      // Act
      ViewResult result = theController.About() as ViewResult;

      // Assert
      Assert.IsNotNull(result);
    }
  }
}
